package com.csii.user.mapper;

import java.util.List;

import com.csii.user.entity.SysRole;
import com.csii.user.entity.SysUserRole;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * <p>
 * 用户角色表 Mapper 接口
 * </p>
 *
 * @Author ian
 * @since 2018-12-21
 */
public interface SysUserRoleMapper extends BaseMapper<SysUserRole> {

	@Select("select role_code from sys_role where id in (select role_id from sys_user_role where user_id = (select id from sys_user where username=#{username}))")
	List<String> getRoleByUserName(@Param("username") String username);

	@Select("select id from sys_role where id in (select role_id from sys_user_role where user_id = (select id from sys_user where username=#{username}))")
	List<String> getRoleIdByUserName(@Param("username") String username);

	@Select("SELECT sr.id, sr.role_name, sr.role_code, sr.description\n" +
			"FROM sys_role sr \n" +
			"LEFT JOIN sys_user_role sur ON sr.id = sur.role_id\n" +
			"WHERE sur.user_id = #{userId} AND sr.role_code = #{roleCode} ")
	SysRole getRoleByUserIdAndRoleCode(@Param("userId") String userId, @Param("roleCode") String roleCode);

}
